package com.winhxd.b2c.product.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductAttributeAndOptionCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductAttributeCondition;
import com.winhxd.b2c.common.domain.product.model.ProductAttribute;
import com.winhxd.b2c.common.domain.product.vo.ProductAttributeAndOptionVO;
import com.winhxd.b2c.common.feign.product.AttributeManagementServiceClient;
import com.winhxd.b2c.product.service.AttributeManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cuipengbo
 * @create 2019-01-07 11:25
 * @desc 商品属性管理
 **/
@Api(value = "Attribute Perfection", tags ="product Attribute")
@RestController
public class ProductAttributeController implements AttributeManagementServiceClient {

    private Logger logger = LoggerFactory.getLogger(ProductAttributeController.class);

    @Autowired
    private AttributeManagementService attributeManagementService;

    @ApiOperation(value = "查询商品属性列表")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<PagedList<ProductAttribute>> findProductAttributeList(@RequestBody ProductAttributeCondition productAttributeCondition) {
        ResponseResult<PagedList<ProductAttribute>> result = new ResponseResult<>();
        PagedList<ProductAttribute> list = attributeManagementService.findProductAttributeList(productAttributeCondition);
        result.setData(list);
        return result;
    }

    /**
     * 商品属性编辑页保存
     * @param productAttributeCondition
     * @return
     */
    @ApiOperation(value = "根据属性id修改商品属性")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> modifyProductAttributeById(@RequestBody ProductAttributeCondition productAttributeCondition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = attributeManagementService.modifyProductAttributeById(productAttributeCondition);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "根据属性id查询属性信息")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<ProductAttributeAndOptionVO> getProductAttributeById(@RequestBody ProductAttributeCondition productAttributeCondition) {
        ResponseResult<ProductAttributeAndOptionVO> result = new ResponseResult<>();
        ProductAttributeAndOptionVO vo = attributeManagementService.getProductAttributeById(productAttributeCondition.getId());
        result.setData(vo);
        return result;
    }


    @ApiOperation(value = "保存属性信息")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> saveOrUpdateProductAttribute(@RequestBody ProductAttributeAndOptionCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = attributeManagementService.saveOrUpdateProductAttribute(condition);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "根据条件查询商品属性信息")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<List<ProductAttribute>> findProductAttributeByModel(@RequestBody ProductAttributeCondition productAttribute) {
        ResponseResult<List<ProductAttribute>> result = new ResponseResult<>();
        List<ProductAttribute> list = attributeManagementService.findProductAttributeByModel(productAttribute);
        result.setData(list);
        return result;
    }



}
